package com.atguigu.gulimall.order.interceptor;

import com.atguigu.common.utils.MemberRespVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class UserLoginInterceptor implements HandlerInterceptor {

    public static ThreadLocal<MemberRespVo> threadLocal = new ThreadLocal<>();

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

        MemberRespVo loginUser = (MemberRespVo) request.getSession().getAttribute("loginUser");
        if (loginUser!=null){
            threadLocal.set(loginUser);
            return true;
        }else{
            response.sendRedirect("http://auth.gulimall.com/login.html");
            return false;
        }

    }
}
